package com.meituan.catering.management.order.biz.model.converter;

import com.meituan.catering.management.order.api.http.model.request.ProduceCateringOrderHttpRequest;
import com.meituan.catering.management.order.biz.model.request.ProduceCateringOrderBizRequest;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/6/1 14:14
 */
public class ProduceCateringOrderBizRequestConverter {
    public static ProduceCateringOrderBizRequest toProduceCateringOrderBizRequest(ProduceCateringOrderHttpRequest produceCateringOrderHttpRequest){
        ProduceCateringOrderBizRequest produceCateringOrderBizRequest = new ProduceCateringOrderBizRequest();
        produceCateringOrderBizRequest.setVersion(produceCateringOrderHttpRequest.getVersion());
        produceCateringOrderBizRequest.setItems(toItem(produceCateringOrderHttpRequest.getItems()));
        return produceCateringOrderBizRequest;
    }

    public static List<ProduceCateringOrderBizRequest.Item> toItem(List<ProduceCateringOrderHttpRequest.Item> itemList){
        List<ProduceCateringOrderBizRequest.Item> items = new LinkedList<>();
        for (ProduceCateringOrderHttpRequest.Item item : itemList) {
            ProduceCateringOrderBizRequest.Item bizItem = new ProduceCateringOrderBizRequest.Item();
            bizItem.setSeqNo(item.getSeqNo());
            bizItem.setVersion(item.getVersion());
            bizItem.setQuantityOnProduce(item.getQuantityOnProduce());
            bizItem.setAccessories(toAccessory(item.getAccessories()));
            items.add(bizItem);
        }
        return items;
    }

    public static List<ProduceCateringOrderBizRequest.Item.Accessory> toAccessory(List<ProduceCateringOrderHttpRequest.Item.Accessory> accessoryList){
        List<ProduceCateringOrderBizRequest.Item.Accessory> accessories = new LinkedList<>();
        for (ProduceCateringOrderHttpRequest.Item.Accessory accessory : accessoryList) {
            ProduceCateringOrderBizRequest.Item.Accessory bizAccessory = new ProduceCateringOrderBizRequest.Item.Accessory();
            bizAccessory.setSeqNo(accessory.getSeqNo());
            bizAccessory.setVersion(accessory.getVersion());
            bizAccessory.setQuantityOnProduce(accessory.getQuantityOnProduce());
            accessories.add(bizAccessory);
        }
        return accessories;
    }
}
